package top.aicats.blog.BlogManage.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.aicats.blog.BlogManage.mapper.UserMapper;
import top.aicats.blog.BlogManage.model.Users;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

/**
 * @author sjc
 * @version 1.0
 * @date 2020/1/5 15:18
 * @email 952491025@qq.com
 */
@Service
public class UserManageImpl implements IUserManageService {

    @Autowired
    UserMapper userMapper;

    @Override
    public int addOneUser(Users user) {
        user.setUserRefid(UUID.randomUUID().toString().replaceAll("-", ""));
        user.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return userMapper.insert(user);
    }

    @Override
    public List<Users> getAllUsers() {
        return userMapper.selectAllUsers();
    }

    @Override
    public Boolean IsUserNameExist(String username) {
        Users user = new Users();
        user.setUserName(username);
        Users resultUser = userMapper.selectUserByUsername(user);
        if (resultUser != null) {
            return true;
        } else {
            return false;
        }
    }
}
